<template>
  <div class="activity-detail">
    <div class="activity-header">
      <button class="back-btn" @click="$router.back()">
        <span>←</span> 返回
      </button>
    </div>

    <div class="activity-container" v-if="activity">
      <!-- 活动封面 -->
      <div class="activity-banner">
        <img :src="activity.image" :alt="activity.title" />
        <div class="activity-status-badge" :class="activity.status">
          {{ activity.statusText }}
        </div>
      </div>

      <!-- 活动信息 -->
      <div class="activity-info">
        <h1 class="activity-title">{{ activity.title }}</h1>
        
        <div class="activity-meta">
          <div class="meta-item">
            <span class="meta-icon">⏰</span>
            <div class="meta-content">
              <span class="meta-label">活动时间</span>
              <span class="meta-value">{{ activity.endTime }}</span>
            </div>
          </div>
          <div class="meta-item">
            <span class="meta-icon">👥</span>
            <div class="meta-content">
              <span class="meta-label">参与人数</span>
              <span class="meta-value">{{ activity.participants }}人</span>
            </div>
          </div>
        </div>

        <!-- 活动详情 -->
        <div class="activity-content">
          <h2>活动详情</h2>
          <div class="content-section">
            <h3>🎁 活动奖励</h3>
            <p>{{ activity.reward }}</p>
          </div>

          <div class="content-section">
            <h3>📋 参与方式</h3>
            <ul>
              <li v-for="(rule, index) in activity.rules" :key="index">{{ rule }}</li>
            </ul>
          </div>

          <div class="content-section">
            <h3>📝 活动说明</h3>
            <p>{{ activity.description }}</p>
            <p v-for="(note, index) in activity.notes" :key="index" class="note-item">
              {{ note }}
            </p>
          </div>

          <div class="content-section" v-if="activity.terms">
            <h3>⚠️ 注意事项</h3>
            <ul>
              <li v-for="(term, index) in activity.terms" :key="index">{{ term }}</li>
            </ul>
          </div>
        </div>

        <!-- 参与按钮 -->
        <div class="action-buttons">
          <button class="participate-btn" @click="handleParticipate">
            {{ activity.buttonText }}
          </button>
        </div>
      </div>
    </div>

    <div v-else class="loading">
      <p>加载中...</p>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import nanboImage from '@/assets/0d55d67b4b999d6bd61b5cf5b5215328.jpg'

const route = useRoute()
const router = useRouter()
const activity = ref(null)

// 活动数据
const activityData = {
  1: {
    id: 1,
    title: '注册成功送一元南波币',
    description: '新用户注册即可获得1元南波币奖励，快来加入我们的数字藏品社区吧！',
    image: nanboImage,
    status: 'hot',
    statusText: '火热进行中',
    endTime: '长期有效',
    participants: 3456,
    reward: '新用户首次登录成功后，系统将自动发放1元南波币到您的账户，可用于平台内的各种消费和交易。',
    rules: [
      '访问登录页面，新用户系统会自动识别并完成注册',
      '首次登录成功后即可自动获得奖励',
      '每个用户仅限参与一次',
      '奖励将在首次登录成功后立即到账'
    ],
    notes: [
      '南波币是平台内的虚拟货币，可用于购买数字藏品、参与社区活动等。',
      '南波币不可提现，但可以在平台内自由交易和使用。',
      '本活动长期有效，新用户首次登录即可领取。'
    ],
    terms: [
      '请确保登录信息真实有效',
      '禁止使用虚假信息或批量注册账号',
      '违规账号将被取消活动资格',
      '平台保留活动最终解释权'
    ],
    buttonText: '立即登录领取'
  }
}

onMounted(() => {
  const activityId = parseInt(route.params.id)
  activity.value = activityData[activityId]
  
  if (!activity.value) {
    router.push('/')
  }
})

const handleParticipate = () => {
  const token = localStorage.getItem('token')
  if (token) {
    alert('您已经领取过奖励了！')
  } else {
    router.push('/user/login')
  }
}
</script>

<style scoped>
.activity-detail {
  min-height: 100vh;
  background: #f8fafc;
  padding-bottom: 40px;
}

.activity-header {
  background: white;
  padding: 16px 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: #3b82f6;
  font-size: 1rem;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.back-btn:hover {
  background: #eff6ff;
}

.back-btn span {
  font-size: 1.2rem;
}

.activity-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}

.activity-banner {
  position: relative;
  width: 100%;
  height: 400px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  margin-bottom: 30px;
}

.activity-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.activity-status-badge {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 8px 20px;
  border-radius: 25px;
  font-weight: 600;
  font-size: 0.9rem;
  backdrop-filter: blur(10px);
}

.activity-status-badge.hot {
  background: rgba(239, 68, 68, 0.9);
  color: white;
}

.activity-status-badge.active {
  background: rgba(34, 197, 94, 0.9);
  color: white;
}

.activity-info {
  background: white;
  border-radius: 16px;
  padding: 30px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.activity-title {
  font-size: 2rem;
  color: #1e293b;
  margin-bottom: 24px;
  font-weight: 700;
}

.activity-meta {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  margin-bottom: 30px;
  padding: 20px;
  background: #f8fafc;
  border-radius: 12px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.meta-icon {
  font-size: 1.8rem;
}

.meta-content {
  display: flex;
  flex-direction: column;
}

.meta-label {
  font-size: 0.85rem;
  color: #64748b;
  margin-bottom: 4px;
}

.meta-value {
  font-size: 1rem;
  color: #1e293b;
  font-weight: 600;
}

.activity-content {
  margin-top: 30px;
}

.activity-content > h2 {
  font-size: 1.5rem;
  color: #1e293b;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 2px solid #e2e8f0;
}

.content-section {
  margin-bottom: 28px;
}

.content-section h3 {
  font-size: 1.2rem;
  color: #334155;
  margin-bottom: 12px;
  font-weight: 600;
}

.content-section p {
  color: #475569;
  line-height: 1.8;
  margin-bottom: 12px;
}

.content-section ul {
  list-style: none;
  padding: 0;
}

.content-section li {
  color: #475569;
  line-height: 1.8;
  padding-left: 24px;
  position: relative;
  margin-bottom: 8px;
}

.content-section li::before {
  content: '•';
  position: absolute;
  left: 8px;
  color: #3b82f6;
  font-weight: bold;
}

.note-item {
  padding: 12px;
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  border-radius: 4px;
  margin-bottom: 12px;
}

.action-buttons {
  margin-top: 40px;
  display: flex;
  justify-content: center;
}

.participate-btn {
  padding: 16px 60px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.participate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.participate-btn:active {
  transform: translateY(0);
}

.loading {
  text-align: center;
  padding: 60px 20px;
  color: #64748b;
  font-size: 1.1rem;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .activity-container {
    padding: 15px;
  }

  .activity-banner {
    height: 250px;
    margin-bottom: 20px;
  }

  .activity-info {
    padding: 20px;
  }

  .activity-title {
    font-size: 1.5rem;
    margin-bottom: 20px;
  }

  .activity-meta {
    grid-template-columns: 1fr;
    gap: 15px;
    padding: 15px;
  }

  .activity-content > h2 {
    font-size: 1.3rem;
  }

  .content-section h3 {
    font-size: 1.1rem;
  }

  .participate-btn {
    width: 100%;
    padding: 14px 40px;
  }
}

@media (max-width: 480px) {
  .activity-banner {
    height: 200px;
    border-radius: 12px;
  }

  .activity-info {
    padding: 16px;
  }

  .activity-title {
    font-size: 1.3rem;
  }

  .meta-icon {
    font-size: 1.5rem;
  }

  .meta-value {
    font-size: 0.9rem;
  }

  .content-section h3 {
    font-size: 1rem;
  }

  .content-section p,
  .content-section li {
    font-size: 0.9rem;
  }
}
</style>
